package org.wkg.lesson12;

import java.util.concurrent.TimeUnit;

public class Demo_1202 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() -> {
            System.out.println("t1申请locker1");
               synchronized(locker1){
                   System.out.println("t1获取到了locker1锁");
                   try {
                       TimeUnit.SECONDS.sleep(1);
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
                   synchronized(locker2){
                       System.out.println("t1获取到了所有锁资源");
                   }
               }
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2申请locker2");
            synchronized(locker2){
                System.out.println("t2获得了locker2锁");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker1){
                    System.out.println("t2获取到了所有的锁资源");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
